package com.uw.scenic.advice;

import com.uw.scenic.exception.BizException;
import com.uw.scenic.vo.R;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

/**
 * 全局异常处理
 */
@RestControllerAdvice
public class GlobalExceptionAdvice {


    /**
     * 对BizException业务异常进行统一处理
     * @param request
     * @param ex
     * @return
     */
    @ExceptionHandler(value = BizException.class)
    public R<String> handlerCouponException(
            HttpServletRequest request, BizException ex){
        //异常可以定义枚举
        return R.fail(-1,"bussiness error");
    }

}
